package polarizedMF;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class Step7_Ordinal_GroundTruth {

	/**
	 * @param args
	 */
	
	public Step7_Ordinal_GroundTruth(String svm_dataset, String fold, String epsilon) throws IOException {

		BufferedReader br = new BufferedReader(new FileReader(svm_dataset+"fold-"+fold+"\\test0"+epsilon+""));
		BufferedReader br2 = new BufferedReader(new FileReader(svm_dataset+"fold-"+fold+"\\test0"+epsilon+"_"));
		BufferedWriter bw = new BufferedWriter(new FileWriter(svm_dataset+"fold-"+fold+"\\groundtruth0"+epsilon+""));

//		BufferedReader br = new BufferedReader(new FileReader(svm_dataset+"fold-"+fold+"\\train0"+epsilon+""));
//		BufferedReader br2 = new BufferedReader(new FileReader(svm_dataset+"fold-"+fold+"\\train0"+epsilon+"_"));
//		BufferedWriter bw = new BufferedWriter(new FileWriter(svm_dataset+"fold-"+fold+"\\groundtruth0"+epsilon+""));
		
		String line;
		String line2;
		int i=0;
		int total=0;
		int numpos = 0;
		int numneu = 0;
		int numneg = 0;

		while((line = br.readLine()) != null){
			line2 = br2.readLine();
			
			if(line == null || line2 == null)
				break;
			
			String[] l = line.split(" ");
			Double cls = Double.parseDouble(l[0]);
			
			String[] l2 = line2.split(" ");
			Double cls2 = Double.parseDouble(l2[0]);
			
			if(cls > 0 && cls2 < 0) {
				bw.write("1"+"\n");
				total++;
				numpos++;
			}
			else if(cls < 0 && cls2 < 0) {
				bw.write("0"+"\n");
				total++;
				numneu++;
			}
			else if(cls < 0 && cls2 > 0){
				bw.write("-1"+"\n");
				total++;
				numneg++;
			}
			
			i++;
		}
		br.close();
		br.close();
		bw.close();
		
		System.out.println("Percentage of positive rating: "+numpos*100/(double)total);
		System.out.println("Percentage of neutral rating: "+numneu*100/(double)total);
		System.out.println("Percentage of negative rating: "+numneg*100/(double)total);
		System.out.println("Total "+total);
	}

}
